package com.whw.fy.controller;

import com.whw.fy.entity.Message;
import com.whw.fy.entity.Room;
import com.whw.fy.entity.TrainingInstitutionRecords;
import com.whw.fy.service.TrainingInstitutionRecordsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;

@Api(tags = "既往训练机构记录模块")
@RestController
@RequestMapping("/api/trainingInstitutionRecords")
public class TrainingInstitutionRecordsController {
    @Resource
    private TrainingInstitutionRecordsService trainingInstitutionRecordsService;

    @ApiOperation(value = "新增既往训练机构记录")
    @PostMapping("/")
    public Message insert(TrainingInstitutionRecords records) throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        if (records.getTimeStarttoString()!=null)
        records.setTimeStart(simpleDateFormat.parse(records.getTimeStarttoString()));
        if (records.getTimeEndtoString()!=null)
        records.setTimeEnd(simpleDateFormat.parse(records.getTimeEndtoString()));
        return trainingInstitutionRecordsService.insertSelective(records);
    }

    @ApiOperation(value = "根据id删除既往训练机构记录")
    @DeleteMapping("/")
    public Message delete(int id){
        return trainingInstitutionRecordsService.deleteByPrimaryKey(id);
    }

    @ApiOperation(value = "修改既往训练机构记录")
    @PutMapping("/")
    public Message update(TrainingInstitutionRecords records)throws ParseException{
        return trainingInstitutionRecordsService.updateByPrimaryKeySelective(records);
    }

    @ApiOperation(value = "根据id查看既往训练机构记录")
    @GetMapping("/")
    public Message selectById(int id){
        return trainingInstitutionRecordsService.selectByPrimaryKey(id);
    }

}
